package com.fanfanwang.ffw.app.asynctask;

import java.util.LinkedHashMap;

import android.app.Activity;
import android.text.TextUtils;
import android.widget.Toast;

import com.fanfanwang.ffw.app.AppConstant;
import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.bean.SucUpdateUserinfoBean;
import com.fanfanwang.ffw.app.common.Md5Util;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.net.HttpRequest.HttpRequestException;
import com.fanfanwang.ffw.app.net.IssAsyncTask;
import com.fanfanwang.ffw.app.net.IssNetLib;
import com.fanfanwang.ffw.app.net.WebServiceHelper;

public class UpdateUserinfoAsyncTask extends
		IssAsyncTask<String, String, SucUpdateUserinfoBean> {
	private Activity mActivity;
	private String userid;
	private String mobile;
	private String nick_name;
	private String sex;
	private String car_number;
	private String frame_number;
	private String engine_number;

	public UpdateUserinfoAsyncTask(Activity activity, String userid,
			String nick_name, String sex, String car_number,
			String frame_number, String engine_number) {
		super(activity);
		mActivity = activity;
		this.userid = userid;
		this.nick_name = nick_name;
		this.sex = sex;
		this.car_number = car_number;
		this.frame_number = frame_number;
		this.engine_number = engine_number;
	}

	@Override
	protected SucUpdateUserinfoBean doInBackground(String... params) {
		// TODO addAuctionPrice($apiusername,$apipassword,$userid,$pid,$price)
		SucUpdateUserinfoBean bean = null;
		LinkedHashMap<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		paramsMap.put("apiusername", "parking");
		paramsMap.put("apipassword", Md5Util.getMD5To32("parking"));
		paramsMap.put("userid", userid);
		paramsMap.put("nick_name", nick_name);
		paramsMap.put("sex", sex);
		paramsMap.put("car_number", car_number);
		paramsMap.put("frame_number", frame_number);
		paramsMap.put("engine_number", engine_number);
		try {
			bean = IssNetLib.getInstance(mActivity).getUpdateUserinfo(
					WebServiceHelper._UPDATEUSERINFO, paramsMap);
		} catch (HttpRequestException e) {
			e.printStackTrace();
			// exception = getResources().getString(R.string.e_net_error);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			// exception = getResources().getString(R.string.e_json);
		}
		return bean;
	}

	@Override
	protected void onPostExecute(SucUpdateUserinfoBean result) {
		super.onPostExecute(result);
		if (exception != null) {
			ToastAlone.showToast(mActivity, exception);
			return;
		}
		if (result != null) {
			if (result.status == 1) {
				ToastAlone.showToast(mActivity,
						AppConstant.URLDecoderString(result.msg),
						Toast.LENGTH_SHORT).show();
			} else if (result.status == 0) {
				if (!TextUtils.isEmpty(result.msg)) {
					ToastAlone.showToast(mActivity,
							AppConstant.URLDecoderString(result.msg),
							Toast.LENGTH_SHORT).show();
				} else {
					ToastAlone.showToast(
							mActivity,
							mActivity.getResources().getString(
									R.string.e_net_error)).show();
				}

			}
		}
	}
}
